# 数组二分查找
import random
from random import randint
import bisect

lst = []
SIZE = 10
random.seed(5)
for _ in range(SIZE):
    item = randint(1, SIZE)
    bisect.insort(lst, item)
    print('%2d ->' % item, lst)
'''
10 -> [10]
 5 -> [5, 10]
 6 -> [5, 6, 10]
 9 -> [5, 6, 9, 10]
 1 -> [1, 5, 6, 9, 10]
 8 -> [1, 5, 6, 8, 9, 10]
 4 -> [1, 4, 5, 6, 8, 9, 10]
 1 -> [1, 1, 4, 5, 6, 8, 9, 10]
 3 -> [1, 1, 3, 4, 5, 6, 8, 9, 10]
 2 -> [1, 1, 2, 3, 4, 5, 6, 8, 9, 10]
'''

# 用于数字表查询
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
    i = bisect.bisect(breakpoints, score)
    return grades[i]


grade = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
print(grade)  # ['F', 'A', 'C', 'C', 'B', 'A', 'A']
